package collection;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;

public class SortListDemo02 {
    public static void main(String[] args) {
        List<Point>list = new ArrayList<>();
        Random r = new Random();
        for (int i = 0; i < 5; i++) {
            Point p = new Point(r.nextInt(20),r.nextInt(20));
            list.add(p);
        }
        System.out.println(list);
//        Collections.sort(list, (o1,o2)->o1.getX() != o2.getX()? o1.getX()- o2.getX() : o1.getY()-o2.getY());
        Collections.sort(list, (o1,o2)->o1.getX()*o1.getX()+o1.getY()* o1.getY()- o2.getX()*o2.getX()-o2.getY()*o2.getY());
        System.out.println(list);
    }
}
